package 可变参数;

public class int_cancreate {
    public static void main(String[] args) {
        //1.可不传参数
        System.out.println(sum());
        //2.传一个参数
        System.out.println(sum(1));
        //3.传多个参数
        System.out.println(sum(1, 2));
        //4.传数组
        int[] s={1,9,8,4};
        System.out.println(sum(s));
    }//只能定义一个可变参数且只能放在最后面
    public static int sum(int... a){
//a就相当于一个数组
        System.out.println("个数:"+a.length);
        int s=0;
        for (int i = 0; i < a.length; i++) {
            s+=a[i];
        }
        return s;
    }
}
